package com.suse.warmstill.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.BeanUtils;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.suse.warmstill.common.model.ListPageModel;
import com.suse.warmstill.entity.TbDoctor;
import com.suse.warmstill.entity.TbMenu;
import com.suse.warmstill.mapper.TbDoctorMapper;

import com.suse.warmstill.service.BaseService;
import com.suse.warmstill.service.DOkerWxService;
import com.suse.warmstill.vo.ConditionVO;
import com.suse.warmstill.vo.DockerIndexVo;

import com.suse.warmstill.vo.DockerWxVo;
import com.suse.warmstill.vo.ResourceVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * @author 黄靖
 * @author 2022-11-04 12:07
 * description:
 **/
@Service
public class DOkerServiceImpl implements DOkerWxService, BaseService<DockerWxVo, TbDoctor> {
    @Resource
    private TbDoctorMapper doctorMapper;

    @Override
    public ListPageModel<DockerIndexVo> list(ConditionVO conditionVO) {
        final LambdaQueryWrapper<TbDoctor> tbMenuLambdaQueryWrapper = new LambdaQueryWrapper<>();
        final Page<TbDoctor> tbMenuPage = new Page<>(conditionVO.getCurrent(), conditionVO.getSize());

        final Page<TbDoctor> tbResourcePage = doctorMapper.selectPage(tbMenuPage, tbMenuLambdaQueryWrapper);

        final ArrayList<DockerIndexVo> dockerIndexVos = new ArrayList<>();
        tbResourcePage.getRecords().forEach((docker) -> {
            final DockerIndexVo dockerIndexVo = new DockerIndexVo();
            dockerIndexVo.setId(docker.getId());
            dockerIndexVo.setName(docker.getName());
            dockerIndexVo.setPhotoAddress(docker.getPhotoAddress());
            dockerIndexVo.setDepartment(docker.getDepartment());
            dockerIndexVo.setContent(docker.getContent());
            dockerIndexVos.add(dockerIndexVo);
        });

        final ListPageModel<DockerIndexVo> resourceVoListPageModel = new ListPageModel<>();
        resourceVoListPageModel.setList(dockerIndexVos);
        resourceVoListPageModel.setCurrentPage((int) tbResourcePage.getCurrent());
        resourceVoListPageModel.setPageCount((int) tbResourcePage.getPages());
        resourceVoListPageModel.setPageSize((int) tbResourcePage.getSize());
        resourceVoListPageModel.setDataSize((int) tbResourcePage.getTotal());


        return resourceVoListPageModel;
    }

    @Override
    public DockerWxVo getOne(Integer id) {
        final TbDoctor doctor = doctorMapper.selectById(id);
        if(ObjectUtils.isEmpty(doctor)){
            return null;
        }
        return toVo(doctor);
    }

    @Override
    public DockerWxVo toVo(TbDoctor entity) {

        final DockerWxVo dockerWxVo = new DockerWxVo();
        dockerWxVo.setDepartment(entity.getDepartment());
        dockerWxVo.setGender(entity.getGender());
        dockerWxVo.setContent(entity.getContent());
        dockerWxVo.setHostal(entity.getHostal());
        dockerWxVo.setIntroduce(entity.getIntroduce());
        dockerWxVo.setId(entity.getId());
        dockerWxVo.setName(entity.getName());
        dockerWxVo.setPhotoAddress(entity.getPhotoAddress());
        dockerWxVo.setContent(entity.getContent());
        dockerWxVo.setIntroduce(entity.getIntroduce());


        return dockerWxVo;
    }
}
